package com.ghn.cocknovel.ext

import com.google.gson.Gson
import com.kt.NetworkModel.bean.LoginBean
import com.kt.NetworkModel.utils.MVUtils

/**
 *@author: Administrator
 *2023/10/12
 *desc:获取用户token
 */
/**
 * 获取用户登陆Token
 */
fun MVUtils.getUserToken(): String {
    val userData = getString("userData").toString()
    return if (userData.isEmpty()) "" else Gson().fromJson(userData, LoginBean::class.java).token
}

/**
 * 设置当前是否登陆
 */
fun MVUtils.setIsLogin(isLogin: Boolean) {
    put("isLogin", isLogin)
}

/**
 * 判断当前是否登陆
 */
fun MVUtils.IsLogin(): Boolean {
    return getBoolean("isLogin", false)
}

fun MVUtils.setUserAccount(account: String?) {
    if (account != null && account.isNotEmpty()) {
        put("userAccount", account)
    }
}

fun MVUtils.setUserPassWord(userPassWord: String) {
    put("userPassWord", userPassWord)
}

fun MVUtils.getUserAccount(): String? {
    return getString("userAccount", "")
}

fun MVUtils.getUserPassWord(): String? {
    return getString("userPassWord", "")
}